package com.pubinfo.passbook.api.controller.auth;

import com.pubinfo.passbook.api.eip.UserInfoService;
import com.pubinfo.passbook.common.entity.TSystemRole;
import com.pubinfo.passbook.common.entity.TWiteoffInstance;
import com.pubinfo.passbook.common.model.bo.witeoff.QueryWiteoffInstanceParam;
import com.pubinfo.passbook.common.model.ruler.UserAcc;
import com.pubinfo.passbook.common.model.vo.base.JsonResult;
import com.pubinfo.passbook.common.model.vo.base.MyPage;
import com.pubinfo.passbook.common.service.master.TWiteoffInstanceService;
import com.pubinfo.passbook.common.service.master.TWriteoffDataUserService;
import com.pubinfo.passbook.common.service.ruler.CheckService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping(value = "twiteoff")
@Api(tags = "报账管理")
@Slf4j
public class TWiteoffInstanceController {
  
  @Autowired
  TWiteoffInstanceService instanceService;
  @Autowired
  TWriteoffDataUserService userService;
  @Resource
  UserInfoService userInfoService;
  @Autowired
  CheckService checkService;
  
  @PostMapping(value = "query")
  @ApiOperation(value = "报账单列表查询")
  public JsonResult<MyPage<TWiteoffInstance>> queryTWiteoffInstance(@RequestBody QueryWiteoffInstanceParam instanceParam) {
    TSystemRole role = userInfoService.getRoleInfo();
    return JsonResult.success(instanceService.QueryTwiteoffInstance(instanceParam, role, userInfoService.getCurrentUserInfo()));
  }
  
  @PostMapping("select")
  @ApiOperation("报账单查询")
  public JsonResult<TWiteoffInstance> selectTWiteoffInstance(String id) {
    
    TSystemRole systemRole = userInfoService.getRoleInfo();
    String jthrLoginName = userInfoService.getCurrentUserInfo().getJthrLoginName();
    return JsonResult.success(instanceService.getTwiteoffInstanceById(id, systemRole, jthrLoginName));
  }
  
  @GetMapping("user")
  @ApiOperation("根据acct查询用户信息")
  public JsonResult<UserAcc> user(String acct) {
    
    return JsonResult.success(checkService.getUserAcc(acct,true));
  }
  
  @GetMapping("syncData")
  @ApiOperation("syncData")
  public JsonResult<Long> syncData() {
    
    return JsonResult.success(userService.syncData());
  }
}
